var mySwiper = new Swiper('.swiper-container', {
	autoplay: 7000,//可选选项，自动滑动
	loop:true,
	autoplayDisableOnInteraction:false
})
//活动轮播
var activitySwiper = new Swiper('.activity-swiper', {
		freeMode : true,
		slidesPerView:'4',
		initialSlide :$(".activity-swiper").find(".active").parents("li").index(),
	})
window.onscroll = function(){
	lazyLoad($(".lazy[data-load='false']"));
}
$(".lazy").css({
	opacity:0,
	visibility: 'hidden',
	transition: 'all .5s ease-in-out'
})
$(".lazy").load(function(){
	console.log("我出来了！");
	console.log($(this));
	$(this).css({
		opacity:1,
		visibility: 'visible',
	})
})
$(".item_list").find(".product").each(function(){
	var id  = $(this).attr("id");
	console.log(id);
	new timer().showTime({
		container_id:'#'+id,
		start:parseInt($("#"+id).find(".time-container").attr("data-start")),
		now:parseInt($("#"+id).find(".time-container").attr("data-now")),
		end:parseInt($("#"+id).find(".time-container").attr("data-end")),
		callback:function(){
			console.log(this.container_id);
		$(this.container_id).fadeOut(function(){
			$(this).remove();
		})
	}
	}).countDown();
})
//图片格式化
var FormatImg = function(selected,container){
			selected.each(function(){
				var imgsrc =  $(this).attr("data-src");
				var wImage = $(this);
				var imgobj = new Image();
				imgobj.onload = function(){
				var h = this.height;
				var w = this.width;
				var winWidth = container.width();
				var winHeight = container.height();
				var rh = winWidth*h/w;
				var rw = winHeight*w/h;
				var paddingLeft = parseInt((winWidth-rw)/2);
				var paddingTop = parseInt((winHeight-rh)/2);
				if(h/w>winHeight/winWidth)	{
					wImage.attr("src",imgsrc).css("height",winHeight).css("padding-left",paddingLeft);
				}else{
					wImage.attr("src",imgsrc).css("width","100%").css("padding-top",paddingTop);
				}
			}
			imgobj.src = imgsrc;
				
			})
		}
FormatImg($(".format"),$(".format").parents(".swiper-container"));
//判断顶部
if($(".activity-swiper").find(".swiper-slide").length==1){
	$(".activity-swiper").remove();
	$("body").css("margin-top",0);
}
//格式化图片
FormatImg($(".p-img"),$(".p-img").parents(".product-img"));